//
//  CustomButton.m
//  VaramozhiEditor
//
//  Created by jijo on 4/16/13.
//
//

#import "CustomButton.h"


@implementation CustomButton

@synthesize actionTagg;
@synthesize btndelegate;

- (id)initWithFrame:(CGRect)frame Tag:(NSInteger)actionTag Title:(NSString *)btnTitle Image:(UIImage *)image
{
    self = [super initWithFrame:CGRectMake(0, 0, 44, 35)];
    if (self) {
        // Initialization code
        
        UIButton *btnNewSignature1 = [UIButton buttonWithType:UIButtonTypeCustom];
        UIImage *imgNewSignature1 = image ;//[UIImage imageWithImage:[UIImage imageNamed:imgName] scaledToSize:CGSizeMake(33, 33)];
        [btnNewSignature1 setBackgroundImage:imgNewSignature1 forState:UIControlStateNormal];
        [btnNewSignature1 setFrame:CGRectMake((44-imgNewSignature1.size.width)/2, (26-imgNewSignature1.size.height)/2, imgNewSignature1.size.width, imgNewSignature1.size.height)];
        btnNewSignature1.tag = actionTag;
        //[btnNewSignature1 addTarget:btndelegate action:@selector(buttonClicked:) forControlEvents:UIControlEventTouchUpInside];
        
        
        [self addSubview:btnNewSignature1];
        
        
        UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 26, 44, 10)];
        label.backgroundColor = [UIColor clearColor];
        label.textAlignment = UITextAlignmentCenter;
        
        label.text = btnTitle;
        label.textColor = [UIColor whiteColor];
        label.font = [UIFont systemFontOfSize:10];
        label.adjustsFontSizeToFitWidth = YES;//+20130909
        label.minimumFontSize = 6;
        [self addSubview:label];
        
        self.actionTagg = actionTag;
        
        UITapGestureRecognizer *singleFingerTap = [[UITapGestureRecognizer alloc] initWithTarget:self                                               action:@selector(handleSingleTap:)];
        
        [singleFingerTap setCancelsTouchesInView:NO];
        singleFingerTap.numberOfTapsRequired = 1;
        singleFingerTap.delegate = self;
        
        [self addGestureRecognizer:singleFingerTap];



    }
    return self;
}
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer
{
    return YES;
}
//The event handling method
- (void)handleSingleTap:(UITapGestureRecognizer *)recognizer {
    CGPoint location = [recognizer locationInView:[recognizer.view superview]];
    
    [btndelegate buttonClicked:self.actionTagg];
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect
{
    // Drawing code
}
*/

@end
